package cn.edu.zafu.bigdata.x.zzzznnn.h;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

public class TCPClient {
    public static void main(String[] args) {
        try {
            Socket socket = new Socket("同学的服务器IP地址", 0000);
            System.out.println("已连接到服务器。");
            BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
            BufferedReader userInput = new BufferedReader(new InputStreamReader(System.in));
            while (true) {
                System.out.print("请输入要发送给服务器的消息（输入'quit'退出）：");
                String clientMessage = userInput.readLine();
                if (clientMessage.equals("quit")) {
                    break;
                }
                out.println(clientMessage);
                String serverReply = in.readLine();
                System.out.println("服务器回复： " + serverReply);
            }
            socket.close();
            System.out.println("已与服务器断开连接。");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
